package info.webest.media.image;

import info.webest.media.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.Toast;

public class ImageViewerActivity extends Activity {

	private ImageViewer imageViewer;

	@Override
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);

		imageViewer = new ImageViewer(this);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.image_viewer);

		final Intent intent = getIntent();
		if (intent != null) {
			Bundle b = intent.getExtras();
			if (b != null) {
				String filePath = b.getString("FileName");

				try {
					imageViewer.loadImage(filePath);
				} catch (Exception e) {
					Toast.makeText(
							getApplicationContext(),
							String.format(
									"Failed to load image. Exception: %1$s",
									e.getMessage()), Toast.LENGTH_SHORT).show();
					return;
				} catch (OutOfMemoryError e2) {
					Toast.makeText(getApplicationContext(),
							"Failed to load image. Error: not enough memory",
							Toast.LENGTH_SHORT).show();
					return;
				}
				setContentView(imageViewer);
			}
		}
	}
}
